package com.eduhzy.ttw.clazz.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.clazz.R;
import com.eduhzy.ttw.clazz.mvp.contract.HomeContract;
import com.eduhzy.ttw.clazz.mvp.model.HomeModel;
import com.eduhzy.ttw.clazz.mvp.model.entity.HomeData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-4 9:17:43
 */
@Module
public class HomeModule {
    private HomeContract.View view;

    /**
     * 构建HomeModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public HomeModule(HomeContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    HomeContract.View provideHomeView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    HomeContract.Model provideHomeModel(HomeModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<HomeData> provideLists() {
        return new ArrayList<>();
    }
    @ActivityScope
    @Provides
    BaseQuickAdapter<HomeData, AutoBaseViewHolder> providerAdapter(List<HomeData> lists) {
        return new BaseQuickAdapter<HomeData, AutoBaseViewHolder>(R.layout.clazz_rv_item_home, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, HomeData item) {
                helper.setText(R.id.tv_class_name, item.getClassName());
                helper.setText(R.id.tv_count, item.getUserCount()+"个学生");
                helper.setText(R.id.btn_score, (item.getPraiseScore()-item.getImprovingScore()) + "");
            }
        };

    }
    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager(){
        return new LinearLayoutManager(view.getActivity());
    }

}